/**   
* @Title: OrderCtrl.java 
* @Package com.dkt.wap.web 
* @Description: TODO(用一句话描述该文件做什么) 
* @author A18ccms A18ccms_gmail_com   
* @date 2020年6月29日 下午9:32:49 
* @version V1.0   
*/
package com.dkt.wap.web;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.Errors;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dkt.base.NetConsts;
import com.dkt.base.Resps;
import com.dkt.base.ValidUtil;
import com.dkt.base.domain.Item;
import com.dkt.base.domain.Order;
import com.dkt.wap.service.OrderSrv;
import com.dkt.wap.web.dto.Dto;
import com.dkt.wap.web.dto.ItemDto;
import com.dkt.wap.web.dto.OrderDto;

/**
 * 订单管理控制器
 * @ClassName:  OrderCtrl 
 * @PackageName com.dkt.wap.web 
 * @Description: 订单管理控制器
 * @author xuy
 * @date: 2020年6月29日 下午9:32:49 
 * @version V1.0 
 */
@Controller
public class OrderCtrl {
	
	@Autowired
	private OrderSrv orderSrv;

	/**
	 * 订单列表
	 * @Title: order 
	 * @Description: 订单列表
	 * @return
	 * @return: String  
	 * @throws
	 */
	@RequestMapping("/order")
	private String order() {
		return "order";
	}
	
	/**
	 * 提交订单
	 * @Title: doAddOrder 
	 * @Description: 提交订单 
	 * @return
	 * @return: String  
	 * @throws
	 */
	@RequestMapping("/doAddOrder")
	private String doAddOrder() {
		return "add_order";
	}
	
	
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	@ResponseBody
	public Object list(@Validated(Dto.Srch.class)OrderDto dto, Errors errors, HttpServletResponse response)
			throws Exception {
		if (errors.hasErrors()) {
			return ValidUtil.errResps(response, errors);
		}
		List<Order> orders = orderSrv.orderList(dto);
		Resps<List<Order>> resps = new Resps<>(NetConsts.RC_SUCCESS, new String[] {"list success"});
		resps.setData(orders);
		return resps;
	}
	

	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public Object add(@Validated(Dto.Add.class) OrderDto itemDto, Errors errors, HttpServletResponse response)
			throws Exception {
		if (errors.hasErrors()) {
			return ValidUtil.errResps(response, errors);
		}
		orderSrv.addItem(itemDto);
		return new Resps<>(NetConsts.RC_SUCCESS, null);
	}
	
	
}
